import React from 'react';
import { Modal } from 'antd';
import axios from 'axios';
import {sessionManager} from '../../utils/sessionStorage';
import { injectIntl } from 'react-intl';

class settleAccounts extends React.Component{
    constructor(props){
        super(props)
        this.state = {
            visible: false,
            confirmLoading: false,
            des: []
        }

    }
    componentWillReceiveProps(nextProps){
            this.setState({
                visible: nextProps.visible,
            },()=>{
                if(sessionManager.get('selectStuGroup')&&this.state.visible){
                    this.getCMSRule()
                }
            });
    }
    getCMSRule=()=>{
        let params={
            stubGroupId:sessionManager.get('selectStuGroup').id
        }
        axios.post('/api/stubGroup/billSplit/qry', {...params}).then(res => {
            if(res){
                this.setState({
                    des:res.data
                })
                console.log(this.state.des)
            }
        })
    }
    handleOk = () => {
        this.setState({
            visible: false,
            confirmLoading: false,
        });
    }
    render() {
        const { visible, confirmLoading } = this.state;
        const common = this.props.intl.messages.common;
        const button=this.state.des.map((item,index)=>{
            return(
                <div key={index}>
                    {item.expressionType===3&&<div>{common["Non-participationInSettlement"]}</div>}
                    {item.expressionType===2&&item.billType===0&&<div>{common.energyChargeSeparation}：{item.expressionInfo}%</div>}
                    {item.expressionType===2&&item.billType===1&&<div>{common.serviceChargeSeparation}：{item.expressionInfo}%</div>}
                    {item.expressionType===1&&<div>{common.fixationAmountSettlement}（{item.expressionInfo}/{common.degree}）</div>}
                </div>
            )
        })
        return (
            <div>
                <Modal title={common.SettlementRules}
                       visible={visible}
                       onOk={this.handleOk}
                       confirmLoading={confirmLoading}
                       onCancel={this.props.handleCancel}
                       footer={[<div key={1} style={{height:22}}></div>]}
                >
                    <div>
                        {button}
                    </div>
                </Modal>
            </div>
        );
    }
}
export default injectIntl(settleAccounts)